package com.catmiao.rdd.operate.transform;

import com.google.common.collect.Lists;
import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;

import java.util.ArrayList;

/**
 * @author ChengMiao
 * @title: Transfer_01_Map
 * @projectName spark_study
 * @description: TODO
 * @date 2024/11/25 16:27
 */
public class Transfer_09_sortBy {

    public static void main(String[] args) throws InterruptedException {

        final SparkConf conf = new SparkConf();
        conf.setAppName("appName");
        conf.setMaster("local[*]");

        final JavaSparkContext jsc = new JavaSparkContext(conf);


        ArrayList<Integer> list = Lists.newArrayList(2,6,1,5,78,18);
        JavaRDD<Integer> rdd = jsc.parallelize(list, 3);

        /**
         * sortBy：排序
         *      - param1 排序逻辑
         *      - param2 是否升序 true升序 false降序
         *      - param3 分区数量
         */

        rdd
                .sortBy(
                        num -> num,true,2
                )
                .collect().forEach(System.out::println);

        jsc.close();


    }
}
